<template>
  <div class="app-container">
<!--    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="产废单位名称" prop="cfEpName">
        <el-input
          v-model="queryParams.cfEpName"
          placeholder="请输入产废单位名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="法人" prop="cfPerson">
        <el-input
          v-model="queryParams.cfPerson"
          placeholder="请输入法人"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="联系电话" prop="cfPhone">
        <el-input
          v-model="queryParams.cfPhone"
          placeholder="请输入联系电话"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="身份证" prop="cfIdCard">
        <el-input
          v-model="queryParams.cfIdCard"
          placeholder="请输入身份证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="经营许可证" prop="cfJyxkz">
        <el-input
          v-model="queryParams.cfJyxkz"
          placeholder="请输入经营许可证"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="固废种类" prop="cfType">
        <el-input
          v-model="queryParams.cfType"
          placeholder="请输入固废种类"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键点经度" prop="cfLg">
        <el-input
          v-model="queryParams.cfLg"
          placeholder="请输入关键点经度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="关键点纬度" prop="cfLt">
        <el-input
          v-model="queryParams.cfLt"
          placeholder="请输入关键点纬度"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="牌照" prop="cfPz">
        <el-input
          v-model="queryParams.cfPz"
          placeholder="请输入牌照"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>-->

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="small"
          @click="handleAdd"
          v-hasPermi="['solidProdution:cfep:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="small"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['solidProdution:cfep:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="small"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['solidProdution:cfep:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="small"
		  :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['solidProdution:cfep:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="cfepList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
<!--      <el-table-column label="产废企业基本信息ID" align="center" prop="cfId" />-->
      <el-table-column label="产废单位名称" align="center" prop="cfEpName" />
      <el-table-column label="法人" align="center" prop="cfPerson" />
      <el-table-column label="联系电话" align="center" prop="cfPhone" />
      <el-table-column label="身份证" align="center" prop="cfIdCard" />
      <el-table-column label="经营许可证" align="center" prop="cfJyxkz" />
<!--      <el-table-column label="固废种类" align="center" prop="cfType" />
      <el-table-column label="关键点经度" align="center" prop="cfLg" />
      <el-table-column label="关键点纬度" align="center" prop="cfLt" />-->
<!--      <el-table-column label="牌照" align="center" prop="cfPz" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="冗余字段" align="center" prop="other" />
      <el-table-column label="冗余字段" align="center" prop="otherOne" />-->
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="small"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['solidProdution:cfep:edit']"
          >修改</el-button>
          <el-button
            size="small"
            @click="handleDelete(scope.row)"
            v-hasPermi="['solidProdution:cfep:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改产废企业基本信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" append-to-body width="30%" >

      <el-form ref="form" :model="form" :rules="rules" class="clearfix " label-width="140px">
        <el-form-item label="产废单位名称" prop="cfEpName">
          <el-input v-model="form.cfEpName" placeholder="请输入产废单位名称" />
        </el-form-item>
        <el-form-item label="法人" prop="cfPerson">
          <el-input v-model="form.cfPerson" placeholder="请输入法人" />
        </el-form-item>
        <el-form-item label="联系电话" prop="cfPhone">
          <el-input v-model="form.cfPhone" placeholder="请输入联系电话" />
        </el-form-item>
        <el-form-item label="身份证" prop="cfIdCard">
          <el-input v-model="form.cfIdCard" placeholder="请输入身份证" />
        </el-form-item>
        <el-form-item label="经营许可证" prop="cfJyxkz">
          <ImageUpload v-model="form.cfJyxkz" placeholder="请输入经营许可证" />
        </el-form-item>
        <el-form-item label="年产生量(吨)" prop="other">
          <el-input v-model="form.other"  placeholder="请输入内容" />
        </el-form-item>
<!--        <el-form-item label="固废种类" prop="cfType">
          <el-input v-model="form.cfType" placeholder="请输入固废种类" />
        </el-form-item>-->
        <el-form-item label="种类和数量">
          <el-row>
            <el-col>
              <div class="weidu" style="display:flex;">
                <div style="width: 35%">
                  <el-input v-model="form.cfType" placeholder="种类"/>
                </div>
                <div style="width: 35%">
                  <el-input v-model="form.otherOne" placeholder="数量"/>
                </div>
                <el-button style="width: 30%; text-align:  center" type="primary" @click="add"  class="edit-add">

                  <span v-if="form.cfType && form.otherOne" @click="editMore "> 编辑</span>
                  <span  v-else>添加更多</span>
                </el-button>
              </div>
            </el-col>
          </el-row>
        </el-form-item>
        <el-form-item label="暂存库危废存储量">
          <el-row>
            <el-col>
              <div class="weidu" style="display:flex;">
                <div style="width: 35%">
                  <el-input v-model="form.cfLg" placeholder="名称"/>
                </div>
                <div style="width: 35%">
                  <el-input v-model="form.cfLt" placeholder="数量"/>
                </div>
                <el-button style="width: 30%; text-align:  center" type="primary" @click="wry_add"  class="edit-add">

                  <span v-if="form.cfLg && form.cfLt" @click="wry_editMore "> 编辑</span>
                  <span v-else>添加更多</span>
                </el-button>
              </div>
            </el-col>
          </el-row>
        </el-form-item>
<!--        <el-form-item label="关键点经度" prop="cfLg">
          <el-input v-model="form.cfLg" placeholder="请输入关键点经度" />
        </el-form-item>
        <el-form-item label="关键点纬度" prop="cfLt">
          <el-input v-model="form.cfLt" placeholder="请输入关键点纬度" />
        </el-form-item>-->
<!--        <el-form-item label="牌照" prop="cfPz">
          <ImageUpload v-model="form.cfPz" placeholder="请输入牌照" />
        </el-form-item>-->
<!--        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>-->

<!--        <el-form-item label="冗余字段" prop="otherOne">
          <el-input v-model="form.otherOne" type="textarea" placeholder="请输入内容" />
        </el-form-item>-->

      </el-form>
      <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center; margin-top:30px">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>


    <el-dialog   :visible.sync="open2" width="40%" >
      <div>
        <div v-for="(item,index) in itemPerson" class="fuliao " style="  margin: 0 auto; margin-bottom: 10px">
          <div class="ful-input">
            <div class="ful-input-box">
              <span>种类</span>
              <el-input v-model="item.x1" style="height: 30px;"></el-input>
            </div>
            <div  class="ful-input-box">
              <span>数量</span>
              <el-input  v-model="item.x2"></el-input>
            </div>
          </div>

          <div  class="ful-btn">
            <el-button type="primary" @click="addMore(index)" style="height: 30px; line-height: 30px;padding: 0;padding-left: 15px; padding-right: 15px">添加</el-button>
            <el-button type="danger" @click="removeMore(index)"  style="height: 30px; line-height: 30px;padding: 0;padding-left: 15px; padding-right: 15px">删除</el-button>
          </div>
        </div>
        <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center;">
          <el-button type="primary" @click="btnMore">确 定</el-button>
          <el-button @click="btnMoreClose">取 消</el-button>
        </div>
      </div>

    </el-dialog>
    <el-dialog   :visible.sync="open3" width="40%" >
      <div>
        <div v-for="(item,index) in itemWry" class="fuliao " style="  margin: 0 auto; margin-bottom: 10px">
          <div class="ful-input">
            <div class="ful-input-box">
              <span>名称</span>
              <el-input v-model="item.x1" style="height: 30px;"></el-input>
            </div>
            <div  class="ful-input-box">
              <span>数量</span>
              <el-input  v-model="item.x2"></el-input>
            </div>
          </div>

          <div  class="ful-btn">
            <el-button type="primary" @click="wry_addMore(index)" style="height: 30px; line-height: 30px;padding: 0;padding-left: 15px; padding-right: 15px">添加</el-button>
            <el-button type="danger" @click="wry_removeMore(index)"  style="height: 30px; line-height: 30px;padding: 0;padding-left: 15px; padding-right: 15px">删除</el-button>
          </div>
        </div>
        <div slot="footer" class="dialog-footer tianjie_button" style="text-align: center;">
          <el-button type="primary" @click="wry_btnMore">确 定</el-button>
          <el-button @click="wry_btnMoreClose">取 消</el-button>
        </div>
      </div>

    </el-dialog>
  </div>
</template>

<script>
import { listCfep, getCfep, delCfep, addCfep, updateCfep, exportCfep } from "@/api/solidProdution/cfep";
import {validatetoTwoPoint,validatePhoneTwo,validateIdNo,validateEMail} from "@/api/validate/validate";


export default {
  name: "Cfep",
  data() {
    return {
      itemPerson:[
        {
          x1:"",
          x2:""
        }
      ],
      itemWry:[
        {
          x1:"",
          x2:""
        }
      ],
      open2:false,
      open3:false,
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 产废企业基本信息表格数据
      cfepList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        cfEpName: null,
        cfPerson: null,
        cfPhone: null,
        cfIdCard: null,
        cfJyxkz: null,
        cfType: null,
        cfLg: null,
        cfLt: null,
        cfPz: null,
        remark: null,
        other: null,
        otherOne: null
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cfEpName: [
          {required: true, message: "名称不能为空", trigger: "blur"}
        ],
        cfPerson: [
          {required: true, message: "法人名称不能为空", trigger: "blur"}
        ],
        cfPhone: [
          {required: true,validator:validatePhoneTwo, trigger: "blur"}
        ],
        cfIdCard: [
          {required: true,validator:validateIdNo,trigger: "blur"}
        ],
      },
    };
  },
  created() {
    this.getList();
  },
  methods: {
    editMore(){
      var X1,X2;
      if( this.form.cfType){
        X1=this.form.cfType.split(",")
      }
      if(  this.form.otherOne){
        X2=this.form.otherOne.split(",")
      }
      var arr=[];
      for(var i=0;i<X1.length;i++){
        arr.push({
          x1:X1[i],
          x2:X2[i]
        })
      }
      this.itemPerson=arr;


    },
    btnMoreClose(){
      this.open2=false;
    },
    btnMore(){
      var arrx1=[];
      var  arrX2=[]
      var stautus;
      var that = this
      this.itemPerson.map(function(item){
        if(item.x1 && item.x2){
          arrx1.push(item.x1);
          arrX2.push(item.x2);
          stautus = true;
          that.open2=false;
        }else{
          stautus = false;
        }
      })
      this.form.cfType=arrx1.join(',')
      this.form.otherOne=arrX2.join(',');
      return stautus;
    },
    removeMore(index){
      if( this.itemPerson.length<=1){
        this.msgError("至少保留一行");
        return;
      }
      this.itemPerson.splice(index, 1)
    },
    add(){
      this.open2=true;
    },
    addMore(index){
      /* var end=this.itemPerson.length-1;
       if( this.itemPerson[end].x1=="" || this.itemPerson[end].x2==""){
         this.msgError("当前行不能为空");
         return;
       }*/
      this.itemPerson.push( {
        x1:"",
        x2:""
      })
    },




    wry_editMore(){
     /* cfLg: null,
        cfLt*/
      var X1,X2;
      if( this.form.cfLg){
        X1=this.form.cfLg.split(",")
      }
      if(this.form.cfLt){
        X2=this.form.cfLt.split(",")
      }
      var arr=[];
      for(var i=0;i<X1.length;i++){
        arr.push({
          x1:X1[i],
          x2:X2[i]
        })
      }
      this.itemWry=arr;
    },
    wry_btnMoreClose(){
      this.open3=false;
    },
    wry_btnMore(){
      var arrx1=[];
      var  arrX2=[]
      var stautus;
      var that = this
      this.itemWry.map(function(item){
        if(item.x1 && item.x2){
          arrx1.push(item.x1);
          arrX2.push(item.x2);
          that.form.cfLg=arrx1.join(',')
          that.form.cfLt=arrX2.join(',');
          stautus = true;
          that.open3=false;
        }else{
          stautus = false;
        }
      })
      return stautus;
    },
    wry_removeMore(index){
      if( this.itemWry.length<=1){
        this.msgError("至少保留一行");
        return;
      }
      this.itemWry.splice(index, 1)
    },
    wry_add(){
      this.open3=true;
    },
    wry_addMore(index){
      /* var end=this.itemPerson.length-1;
       if( this.itemPerson[end].x1=="" || this.itemPerson[end].x2==""){
         this.msgError("当前行不能为空");
         return;
       }*/
      this.itemWry.push( {
        x1:"",
        x2:""
      })
    },
    /** 查询产废企业基本信息列表 */
    getList() {
      this.loading = true;
      listCfep(this.queryParams).then(response => {
        this.cfepList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        cfId: null,
        cfEpName: null,
        cfPerson: null,
        cfPhone: null,
        cfIdCard: null,
        cfJyxkz: null,
        cfType: null,
        cfLg: null,
        cfLt: null,
        cfPz: null,
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        other: null,
        otherOne: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.cfId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加产废企业基本信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const cfId = row.cfId || this.ids
      getCfep(cfId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改产废企业基本信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.cfId != null) {
            updateCfep(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCfep(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const cfIds = row.cfId || this.ids;
      this.$confirm('是否确认删除产废企业基本信息编号为"' + cfIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delCfep(cfIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有产废企业基本信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(() => {
          this.exportLoading = true;
          return exportCfep(queryParams);
        }).then(response => {
          this.download(response.msg);
          this.exportLoading = false;
        }).catch(() => {});
    }
  }
};
</script>

<style lang="postcss" scoped>
.fuliao{
  width: 100%;
  height: 30px;
  display: flex;
  justify-content:  space-around;
  margin-bottom: 10px;
}
.ful-input{
  width: 80%;
  display: flex;
  align-items: center;
  /*justify-content: space-between;*/
}

.ful-title{
  font-size:16px;
  color: #333;
  width: 50%;
  text-align: center;
  font-weight: 700;
}
.fuliao/deep/.el-input__inner{
  width: 100%;
  height: 30px !important;
}
.content-left {
  width: 30% !important;
  float: left;
}
.ful-btn{
  width: 20%;
  margin-left: 10px;
}

.ful-input-box{
  width: 50%;
  font-weight: bold;

  display: flex;
  align-items: center;
  justify-content: space-between;
}
.ful-input-box span{
  text-align: center;
  width: 40%;
  color: #333;
  display: inline-block;
}
.content-middle {
  width: 30%;
  float: left;
  margin-left: 3%;
}

.content-right {
  width: 30%;
  float: left;
  margin-left: 3%;
}

.content-address {
  display: flex;
  width: 100%;
}

.app-container-process {
  padding-left: 60px;
  padding-right: 60px;
}

.title2 {
  height: 40px;
  /*padding: 20px 0;*/

}

.title2 span {
  display: inline-block;
  border-radius: 50%;
  width: 15px;
  height: 15px;
  vertical-align: middle;
  margin-right: 10px;
  background-color: deepskyblue;
}

.avatar-uploader {
  width: 100%;
}

.avatar-uploader .el-upload {
  border: 1px dashed #d9d9d9;
  border-radius: 6px;
  cursor: pointer;
  position: relative;
  overflow: hidden;
}

.avatar-uploader .el-upload:hover {
  border-color: #409EFF;
}

.avatar-uploader-icon {
  font-size: 28px;
  color: #8c939d;
  width: 128px;
  height: 128px;
  line-height: 128px;
  text-align: center;
}

.avatar {
  width: 128px;
  height: 128px;
  display: block;
}

.weidu {
  display: flex;
}
.edit-add{
  padding: 0;
  margin: 0;
  height: 60px;
  line-height: 30px;
  border-radius: 0;
}
</style>
